package com.lanou3g.ptp.api.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import com.lanou3g.ptp.api.resolver.annotation.SsoTeacher;
import com.lanou3g.ptp.entity.Teacher;
import com.lanou3g.ptp.task.service.ExcellentService;
import com.lanou3g.ptp.utils.PtpResult;
import com.lanou3g.ptp.utils.PtpResultUtils;
import com.lanou3g.ptp.vo.ExcellentBody;
import com.lanou3g.ptp.vo.ExcellentParams;
import com.lanou3g.ptp.vo.Option;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 创建人: 武奇
 * 创建事件: 2019/8/29
 * 精选接口
 */
@RestController
@Slf4j
public class ExcellentController {

    @Reference
    private ExcellentService excellentService;

    @ApiOperation("将某个日志进行推优")
    @PostMapping("/excellent/diary/{diaryId}")
    public PtpResult excellentDiary(@PathVariable Long diaryId) {
        this.excellentService.diaryExcellent(diaryId);
        return PtpResultUtils.ok();
    }

    @ApiOperation("将某个阶段报告进行推优")
    @PostMapping("/excellent/report/{reportId}")
    public PtpResult excellentReport(@PathVariable Long reportId) {
        this.excellentService.reportExcellent(reportId);
        return PtpResultUtils.ok();
    }

    @ApiOperation("将某个总结进行推优")
    @PostMapping("/excellent/summary/{summaryId}")
    public PtpResult excellentSummary(@PathVariable Long summaryId) {
        this.excellentService.summaryExcellent(summaryId);
        return PtpResultUtils.ok();
    }

    @ApiOperation("精选年级的查询条件")
    @GetMapping("/option/excellent/grade")
    public PtpResult optionGrades() {
        List<Option> options = this.excellentService.optionGrades();
        return PtpResultUtils.ok(options);
    }

    /**
     * 查询当前登录教师所属的所有精选信息
     * 学院老师：没有专业id，->学院->专业->教学环节->任务->精选报告
     * 专业老师：专业->教学环节->任务->精选报告
     * 7e9fd1b07ca64959871c681ce15b0113
     */
    @ApiOperation("查询当前登录老师所属的精选信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "老师的token", paramType = "header")
    })
    @PostMapping("/excellent/list")
    public PtpResult list(@ApiIgnore @SsoTeacher Teacher teacher, @RequestBody ExcellentParams params) {
        log.info("精选查询参数: {}", params);
        PageInfo<ExcellentBody> pageInfo = this.excellentService.getExcellent(teacher, params);
        return PtpResultUtils.ok(pageInfo);
    }

}
